#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START libssh2
# depends: cmake-native
# depends: openssl1.1

rm -rf build/libssh2
mkdir -p build/libssh2
cd build/libssh2

compiler_sysroot=`${TARGET}-gcc -print-sysroot`
cat > ${TARGET}-toolchain.cmake << EOF
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR ${TARGET##-*})
set(CMAKE_C_COMPILER ${TARGET}-gcc)
set(CMAKE_CXX_COMPILER ${TARGET}-g++)
set(CMAKE_FIND_ROOT_PATH ${stage}${prefix})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
EOF

${xtools}${build_prefix}/bin/cmake \
	-DCMAKE_TOOLCHAIN_FILE="${TARGET}-toolchain.cmake" \
	-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
	-DCMAKE_INSTALL_PREFIX=${prefix} \
	-DCMAKE_INSTALL_LIBDIR=${target_libdir} \
	-DCMAKE_BUILD_TYPE=Release \
	-DBUILD_SHARED_LIBS=OFF \
	-DBUILD_STATIC_LIBS=ON \
	-DCRYPTO_BACKEND=OpenSSL \
	-DENABLE_ZLIB_COMPRESSION=OFF \
	../../libssh2

${xtools}${build_prefix}/bin/cmake \
	--build . --verbose --parallel ${JOBS}

env DESTDIR=`pwd`/inst \
${xtools}${build_prefix}/bin/cmake \
	--build . --verbose \
	-t install

rm -rf inst${prefix}/share
cd inst
find "${prefix#/}" | cpio -pumd "$stage"

cd ../../..
rm -rf build/libssh2

# RECIPE END libssh2
